home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / distutils / tests / test_dist.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  4KB  |  119 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. '''Tests for distutils.dist.'''
  5. import distutils.cmd as distutils
  6. import distutils.dist as distutils
  7. import os
  8. import shutil
  9. import sys
  10. import tempfile
  11. import unittest
  12. from test.test_support import TESTFN
  13.  
  14. class test_dist(distutils.cmd.Command):
  15.     '''Sample distutils extension command.'''
  16.     user_options = [
  17.         ('sample-option=', 'S', 'help text')]
  18.     
  19.     def initialize_options(self):
  20.         self.sample_option = None
  21.  
  22.  
  23.  
  24. class TestDistribution(distutils.dist.Distribution):
  25.     '''Distribution subclasses that avoids the default search for
  26.     configuration files.
  27.  
  28.     The ._config_files attribute must be set before
  29.     .parse_config_files() is called.
  30.     '''
  31.     
  32.     def find_config_files(self):
  33.         return self._config_files
  34.  
  35.  
  36.  
  37. class DistributionTestCase(unittest.TestCase):
  38.     
  39.     def setUp(self):
  40.         self.argv = sys.argv[:]
  41.         del sys.argv[1:]
  42.  
  43.     
  44.     def tearDown(self):
  45.         sys.argv[:] = self.argv
  46.  
  47.     
  48.     def create_distribution(self, configfiles = ()):
  49.         d = TestDistribution()
  50.         d._config_files = configfiles
  51.         d.parse_config_files()
  52.         d.parse_command_line()
  53.         return d
  54.  
  55.     
  56.     def test_command_packages_unspecified(self):
  57.         sys.argv.append('build')
  58.         d = self.create_distribution()
  59.         self.assertEqual(d.get_command_packages(), [
  60.             'distutils.command'])
  61.  
  62.     
  63.     def test_command_packages_cmdline(self):
  64.         sys.argv.extend([
  65.             '--command-packages',
  66.             'foo.bar,distutils.tests',
  67.             'test_dist',
  68.             '-Ssometext'])
  69.         d = self.create_distribution()
  70.         self.assertEqual(d.get_command_packages(), [
  71.             'distutils.command',
  72.             'foo.bar',
  73.             'distutils.tests'])
  74.         cmd = d.get_command_obj('test_dist')
  75.         self.assert_(isinstance(cmd, test_dist))
  76.         self.assertEqual(cmd.sample_option, 'sometext')
  77.  
  78.     
  79.     def test_command_packages_configfile(self):
  80.         sys.argv.append('build')
  81.         f = open(TESTFN, 'w')
  82.         
  83.         try:
  84.             print >>f, '[global]'
  85.             print >>f, 'command_packages = foo.bar, splat'
  86.             f.close()
  87.             d = self.create_distribution([
  88.                 TESTFN])
  89.             self.assertEqual(d.get_command_packages(), [
  90.                 'distutils.command',
  91.                 'foo.bar',
  92.                 'splat'])
  93.             sys.argv[1:] = [
  94.                 '--command-packages',
  95.                 'spork',
  96.                 'build']
  97.             d = self.create_distribution([
  98.                 TESTFN])
  99.             self.assertEqual(d.get_command_packages(), [
  100.                 'distutils.command',
  101.                 'spork'])
  102.             sys.argv[1:] = [
  103.                 '--command-packages',
  104.                 '',
  105.                 'build']
  106.             d = self.create_distribution([
  107.                 TESTFN])
  108.             self.assertEqual(d.get_command_packages(), [
  109.                 'distutils.command'])
  110.         finally:
  111.             os.unlink(TESTFN)
  112.  
  113.  
  114.  
  115.  
  116. def test_suite():
  117.     return unittest.makeSuite(DistributionTestCase)
  118.  
  119.